package com.qianyu.project.mapper.provider.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import javax.websocket.server.ServerEndpoint;
import java.util.List;
import java.util.Map;

@Repository
public interface smjLaberSalaryDao {
    //添加项目工资
    @Insert("insert into project_salary(id, p_id, type, year, menth, apply_date, handler_id, attach_ids) " +
            " value(#{id},#{p_id},#{type},#{year},#{menth},#{apply_date},#{handler_id},#{attach_ids})")
    void AddLaberSalary(String id, String p_id, String type, String year, String menth, String apply_date, String handler_id, String attach_ids);

    //添加工资明细
    @Insert("insert into project_salary_work_list values(null,#{salary_id},#{name},#{type},#{day},#{salaryday},#{salary},#{salaryplus},#{paysalary},#{borrowsalary},#{insurancesalary},#{deductsalary},#{allocatesalary})")
    void AddWorkList(String salary_id, String name, String type, String day, String salaryday, String salary, String salaryplus, String paysalary, String borrowsalary, String insurancesalary, String deductsalary, String allocatesalary);

    //修改审批
    @Update("update project_salary set approve_status =#{approve_status} where id=#{id}")
    void UpdateApproveStatus(int approve_status, String id);

    //查询工资列表
    @SelectProvider(type = smjLaberSalaryProvider.class ,method = "listlabersalary")
    IPage<Map<String, Object>> listlabersalary(IPage<Map<String, Object>> page, Map<String, String> params);

    //查询应发合计
    @Select("select sum(paysalary) from project_salary_work_list where salary_id=#{id}")
    String getYnumber(String id);

    //查询实发合计
    @Select("select sum(allocatesalary) from project_salary_work_list where salary_id=#{id}")
    String getSnumber(String id);

    //查询工资明细
    @Select("select * from project_salary_work_list where salary_id=#{id}")
    List<Map<String, Object>> getWorkList(String id);

    //获取流程id
    @Select("select fid from form  where id=#{id} and target ='project_salary'")
    String getFid(String id);

    //获取审批流程
    @Select("select fa.*,fn.flowNodeName,su.user_realname from form_audit fa ,flow_node fn ,system_user su where fa.fid=#{fid} and fa.flowNodeId = fn.flowNodeId and fa.eid=su.id")
    List<Map<String, Object>> getfromaudit(String fid);
}
